package bb.lanxing.devices.utils;

import android.util.Log;
import bb.lanxing.App;
import bb.lanxing.manager.RemoteServiceManager;

public class DeviceServiceChecker {
    private static DeviceServiceChecker instance;
    private boolean isDeviceServiceStarted = false;

    public static DeviceServiceChecker getInstance() {
        if (instance == null) {
            instance = new DeviceServiceChecker();
        }
        return instance;
    }

    public boolean isDeviceServiceStart() {
        return this.isDeviceServiceStarted;
    }

    public void startDeviceServiceAndAutoConnector() {
        if (!App.getContext().isAppForeground()) {
            Log.w("isAppForeground", "false");
        }
        if (RemoteServiceManager.getInstance().isServiceBind() && App.getContext().isAppForeground()) {
            RemoteServiceManager.getInstance().openBLE();
            Log.w("DeviceServiceChecker", "startDeviceService success");
            this.isDeviceServiceStarted = true;
            return;
        }
        Log.e("DeviceServiceChecker", "remoteService not bind");
        RemoteServiceManager.getInstance().bindWorkoutService();
    }
}
